﻿using System;
using System.Collections.Generic;

namespace Mercenary
{
	public class StraPvpElderGods : IStrategy
	{
		public static string m_name = UiItemConst.策略_PVP古神队.m_name;
		public static int m_mercMax = 6;
		public List<MercCard> m_mercList = new List<MercCard>();

		public string Name() { return m_name; }

		public List<MercCard> GetMercList() { return m_mercList; }

		public (int hand_index, int play_index) GetEnterOrder(
			List<MercCard> hand_mercenaries,
			List<MercCard> play_mercenaries)
		{
			int 变装大师 = UtilsStra.FindMercenaryIndexForName("变装大师", play_mercenaries);
			if (变装大师 == 0)
				return (0, 变装大师);
			else if (变装大师 > 0)
				return (0, 变装大师 + 1);
			return (0, play_mercenaries.Count);
		}

		public void UpdateMercList()
		{
			m_mercList.Clear();
		}

		public List<BattleTarget> GetBattleTargets(
			int turn,
			List<MercCard> targets_opposite_all,
			List<MercCard> targets_friendly_all,
			List<MercCard> targets_opposite_graveyrad)
		{
			List<BattleTarget> list = new List<BattleTarget>();
			var targets_opposite_valid = targets_opposite_all.FindAll(
				(MercCard t) => t.m_enable == true);
			var targets_friendly = targets_friendly_all.FindAll(
				(MercCard t) => t.m_enable == true);

			try
			{
				foreach (var merc_iter in targets_friendly_all)
				{
					if (merc_iter.m_name == "恩佐斯")
					{

						//目前只抓这两个随从，有收益
						if (null != UtilsStra.FindSpecNameTarget("梦魇毒蛇", targets_opposite_all)
						|| null != UtilsStra.FindSpecNameTarget("尤朵拉的火炮", targets_opposite_all)) //如果有随从，优先2技能
						{
							Console.WriteLine("有蛇/火炮");
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("恩佐斯之赐", merc_iter)?.m_id ?? -1,
								m_skillName = "恩佐斯之赐",
							});
						}
						else if (
								(targets_friendly_all.Count == 5 && null ==
								UtilsStra.FindMercenaryForName("克苏恩的触手", targets_friendly_all))
							|| (targets_friendly_all.Count == 6 && null !=
							UtilsStra.FindMercenaryForName("克苏恩的触手", targets_friendly_all))
							|| null != UtilsStra.FindMercenaryForName("贝恩·血蹄", targets_opposite_all)
							)
						{
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("腐化脏器", merc_iter)?.m_id ?? -1,
								m_skillName = "腐化脏器",
							});
						}
						//其他情况默认1技能
						list.Add(new BattleTarget()
						{
							m_skillId = UtilsStra.FindSkillForName("恩佐斯的子嗣", merc_iter)?.m_id ?? -1,
							m_skillName = "恩佐斯的子嗣",
						});
					}
					else if (merc_iter.m_name == "尤格-萨隆")
					{
						List<MercCard> focusTargets = new List<MercCard>();
						focusTargets.Add(UtilsStra.FindSpecNameTarget("克苏恩", targets_friendly_all));
						focusTargets.Add(UtilsStra.FindSpecNameTarget("尤格-萨隆", targets_friendly_all));
						MercCard common_target = UtilsStra.GetTarget(focusTargets);

						if (null != UtilsStra.FindSpecNameTarget("希尔瓦娜斯·风行者", targets_opposite_all)
							|| null != UtilsStra.FindSpecNameTarget("潮汐主母阿茜萨", targets_opposite_all))
						{   //只有娜迦队/或者10速的女王，才有可能让导演放出15速的技能
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("古神在上", merc_iter)?.m_id ?? -1,
								m_skillName = "古神在上",
							});
						}
						if (targets_friendly_all.Count == 1)
						{
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("狂乱凝视", merc_iter)?.m_id ?? -1,
								m_skillName = "狂乱凝视",
							});
						}
						list.Add(new BattleTarget()
						{
							m_oppoTarId = common_target?.m_id ?? -1,
							m_oppoTarName = common_target?.m_name ?? "",
							m_skillId = UtilsStra.FindSkillForName("心灵癫狂", merc_iter)?.m_id ?? -1,
							m_skillName = "心灵癫狂",
						});
					}
					else if (merc_iter.m_name == "亚煞极")
					{
						List<MercCard> focusTargets = new List<MercCard>();
						string[] preKills = new string[]
						{   "瓦莉拉·萨古纳尔","鞭笞者特里高雷",
							"安娜科德拉", "周卓","克苏恩",
							"沃金","艾萨拉女王","魔像师卡扎库斯","恩佐斯","希尔瓦娜斯·风行者",
							"艾德温，迪菲亚首脑","尤朵拉","伊莉斯·逐星",
							"冰雪之王洛克霍拉","巴琳达·斯通赫尔斯",
						};
						for (int i = 0; i < preKills.Length; i++)
						{
							focusTargets.Add(UtilsStra.FindSpecNameTarget(preKills[i], targets_opposite_valid));
						}
						//打绿色
						focusTargets.Add(UtilsStra.FindMinHealthTarget(
							targets_opposite_valid.FindAll((MercCard t) =>
							t.m_role == TAG_ROLE.FIGHTER)));
						//打佣兵
						focusTargets.Add(UtilsStra.FindMinHealthTarget(
							targets_opposite_valid.FindAll((MercCard t) =>
							t.m_role != TAG_ROLE.NEUTRAL && t.m_role != TAG_ROLE.INVALID)));

						MercCard common_target = UtilsStra.GetTarget(focusTargets);

						if ((null != UtilsStra.FindMercenaryForName("克苏恩", targets_friendly_all)
						&& null == UtilsStra.FindMercenaryForName("沃金", targets_friendly_all))
						)
						{   //古神队，克苏恩登场，沃金没上场，减cd
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("无羁之怒", merc_iter)?.m_id ?? -1,
								m_skillName = "无羁之怒",
							});
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("亚煞极之力", merc_iter)?.m_id ?? -1,
								m_skillName = "亚煞极之力",
							});
						}
						else if (turn <= 2)//前两个回合
						{
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("无羁之怒", merc_iter)?.m_id ?? -1,
								m_skillName = "无羁之怒",
							});
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("亚煞极之力", merc_iter)?.m_id ?? -1,
								m_skillName = "亚煞极之力",
							});
						}
						else
						{
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("无羁之怒", merc_iter)?.m_id ?? -1,
								m_skillName = "无羁之怒",
							});
							list.Add(new BattleTarget()
							{
								m_oppoTarId = common_target?.m_id ?? -1,
								m_oppoTarName = common_target?.m_name ?? "",
								m_skillId = UtilsStra.FindSkillForName("亵渎攻击", merc_iter)?.m_id ?? -1,
								m_skillName = "亵渎攻击",
							});
						}

					}
					else if (merc_iter.m_name == "克苏恩")
					{
						List<MercCard> focusTargets = new List<MercCard>();
						string[] preKills = new string[]
						{   "周卓","鞭笞者特里高雷",
							"沃金","尤格-萨隆","贝恩·血蹄","艾萨拉女王","魔像师卡扎库斯","恩佐斯","希尔瓦娜斯·风行者",
							"艾德温，迪菲亚首脑","伊莉斯·逐星",
							"冰雪之王洛克霍拉",
						};
						for (int i = 0; i < preKills.Length; i++)
						{
							focusTargets.Add(UtilsStra.FindSpecNameTarget(preKills[i], targets_opposite_valid));
						}
						//打蓝色
						focusTargets.Add(UtilsStra.FindMinHealthTarget(
							targets_opposite_valid.FindAll((MercCard t) =>
							t.m_role == TAG_ROLE.CASTER)));
						//打佣兵
						focusTargets.Add(UtilsStra.FindMinHealthTarget(
							targets_opposite_valid.FindAll((MercCard t) =>
							t.m_role != TAG_ROLE.NEUTRAL && t.m_role != TAG_ROLE.INVALID)));

						MercCard common_target = UtilsStra.GetTarget(focusTargets);
						if (targets_opposite_all.Count == 1 && targets_opposite_all[0].m_curHealth <= 5 && targets_opposite_all[0].m_name == "克苏恩")
						{
							list.Add(new BattleTarget()
							{
								m_skillId = UtilsStra.FindSkillForName("克苏恩的触手", merc_iter)?.m_id ?? -1,
								m_skillName = "克苏恩的触手",
							});
						}
						list.Add(new BattleTarget()
						{
							m_skillId = UtilsStra.FindSkillForName("克苏恩面具", merc_iter)?.m_id ?? -1,
							m_skillName = "克苏恩面具",
						});

						list.Add(new BattleTarget()
						{
							m_oppoTarId = common_target?.m_id ?? -1,
							m_oppoTarName = common_target?.m_name ?? "",
							m_skillId = UtilsStra.FindSkillForName("精神鞭笞", merc_iter)?.m_id ?? -1,
							m_skillName = "精神鞭笞",
						});
					}
					else if (merc_iter.m_name == "沃金")
					{
						List<MercCard> focusTargets = new List<MercCard>();
						string[] preKills = new string[]
						{   "黄金猿","鞭笞者特里高雷", "艾德温，迪菲亚首脑",
							"伊莉斯·逐星","冰雪之王洛克霍拉","希尔瓦娜斯·风行者","沃金",
							"玉珑", "周卓", "亚煞极","恩佐斯"
						};
						for (int i = 0; i < preKills.Length; i++)
						{
							focusTargets.Add(UtilsStra.FindSpecNameTarget(preKills[i], targets_opposite_valid));
						}
						//打红色
						focusTargets.Add(UtilsStra.FindMinHealthTarget(
							targets_opposite_valid.FindAll((MercCard t) => t.m_role == TAG_ROLE.TANK)));
						MercCard common_target = UtilsStra.GetTarget(focusTargets);
						list.Add(new BattleTarget()
						{
							m_skillId = UtilsStra.FindSkillForName("虚弱诅咒", merc_iter)?.m_id ?? -1,
							m_skillName = "虚弱诅咒",
						});
						list.Add(new BattleTarget()
						{
							m_skillId = UtilsStra.FindSkillForName("暗影涌动", merc_iter)?.m_id ?? -1,
							m_skillName = "暗影涌动",
						});
						list.Add(new BattleTarget()
						{
							m_oppoTarId = common_target?.m_id ?? -1,
							m_oppoTarName = common_target?.m_name ?? "",
							m_skillId = UtilsStra.FindSkillForName("暗影震击", merc_iter)?.m_id ?? -1,
							m_skillName = "暗影震击",
						});
					}
					else if (merc_iter.m_name == "变装大师")
					{


						list.Add(new BattleTarget()
						{
							m_skillId = UtilsStra.FindSkillForName("流变打击", merc_iter)?.m_id ?? -1,
							m_skillName = "流变打击",
						});
						list.Add(new BattleTarget()
						{
							m_skillId = UtilsStra.FindSkillForName("邪恶计谋", merc_iter)?.m_id ?? -1,
							m_skillName = "邪恶计谋",
						});
					}
					else if (merc_iter.m_name.IndexOf("克苏恩的触手") == 0 ||
						merc_iter.m_name.IndexOf("恩佐斯的子嗣") == 0)
					{
						List<MercCard> focusTargets = new List<MercCard>();
						string[] preKills = new string[]
						{   "周卓",
							"艾萨拉女王","魔像师卡扎库斯","恩佐斯","希尔瓦娜斯·风行者",
							"艾德温，迪菲亚首脑","伊莉斯·逐星","鞭笞者特里高雷",
							"冰雪之王洛克霍拉"
						};
						for (int i = 0; i < preKills.Length; i++)
						{
							focusTargets.Add(UtilsStra.FindSpecNameTarget(preKills[i], targets_opposite_valid));
						}
						//打佣兵
						focusTargets.Add(UtilsStra.FindMinHealthTarget(
							targets_opposite_valid.FindAll((MercCard t) =>
							t.m_role != TAG_ROLE.NEUTRAL && t.m_role != TAG_ROLE.INVALID)));

						MercCard common_target = UtilsStra.GetTarget(focusTargets);
						list.Add(new BattleTarget()
						{
							m_oppoTarId = common_target?.m_id ?? -1,
							m_oppoTarName = common_target?.m_name ?? "",
							m_skillId = UtilsStra.FindSkillForName("攻击", merc_iter)?.m_id ?? -1,
							m_skillName = "攻击",
						});
					}
					else if (merc_iter.m_name.IndexOf("盔中寄居蟹") == 0 ||
						merc_iter.m_name.IndexOf("剑鱼") == 0 ||
						merc_iter.m_name.IndexOf("闪光翻车鱼") == 0)
					{
						list.Add(new BattleTarget()
						{
							m_frieTarName = merc_iter.m_name,
							m_bAllowOption = false,
						});
					}
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine("空间名：" + ex.Source + "；" + '\n' +
					"方法名：" + ex.TargetSite + '\n' +
					"故障点：" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' +
					"错误提示：" + ex.Message + '\n' +
					"XXX：" + ex.ToString()
					);
			}

			return list;
		}
	}
}

